//
// Created by 86131 on 2023/12/14.
//

#include <iostream>
#include "../AdjacencyList.h"
#include <algorithm>
using namespace std;

struct node{
    int  a;
    int b;
    int c=1;
};
bool cmp(const node&a,const node&b){
    return a.b<b.b;
}
int main(){
     int m,n;
     cin>>m>>n;
     node k[n];
    AdjacencyList graph(m);
    for(int i=0;i<n;i++){
        cin>>k[i].a>>k[i].b;
    }
    sort(k,k+n,cmp);
    for(int i=0;i<n;i++){
        graph.addEdge(k[i].a,k[i].b,1);
    }
    graph.DFS(0);
}